<template>
  <div class="buttonAddExit">
    <el-button type="primary" size="mini" @click="dialogFormVisibleAdd=true"> 附件 </el-button>
    <el-dialog :close-on-click-modal="false"  title="下载附件" :visible.sync="dialogFormVisibleAdd" @opened="$store.commit('dialogTop')" @close="resetForm('ruleFormAdd')">
      <el-form :model="ruleFormAdd" :rules="rulesAdd" ref="ruleFormAdd" label-width="120px" class="demo-ruleForm">
        <el-form-item label="报送单位" prop="account" :rules="{required: true, message: '企业名称不能为空', }">
          <!--<el-input  size="small" v-model="ruleFormAdd.account" auto-complete="off" placeholder="企业名称"></el-input>-->
          <el-select v-model="ruleFormAdd.account" style="width: 100%;margin-top: 7px;" size="mini" clearable placeholder="全部">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item  prop="account" >
            <i class="el-icon-document" style="font-size: 20px;margin-right: 10px;color:#3975FE;"></i><span style="color:#3975FE;cursor: pointer;">评分依据附件</span>
        </el-form-item>
      </el-form>
      <div style="text-align: center;margin-top: 20px;">
        <el-button  size="small" @click="dialogFormVisibleAdd = false">取 消</el-button>
        <el-button style="margin-left: 20px;" type="primary" size="small" @click="submitForm('ruleFormAdd')">确 定</el-button>
      </div>


    </el-dialog>
  </div>
</template>

<script>

  export default {
    props:["optionsP","optionsP1"],
    data () {
      var phoneCheck = (rule, value, callback) => {
        var phnum = /^1[3456789]{1}\d{9}$/
        if (value === '') {
          callback(new Error('联系电话不能为空'));
        }else if(!phnum.exec(Number(value))){
          callback(new Error('请正确输入手机号！'));
        } else {
          callback();
        }
      };
      var userPasswordCheck = (rule, value, callback) => {
        var pwd= /(?!^(\d+|[a-zA-Z]+|[~!@#$%^&*?]+)$)^[\w~!@#$%\^&*?]{8,}$/;
        if (!value) {
          return callback(new Error('密码不能为空'));
        } else if(!pwd.exec(value)){
          callback(new Error('密码至少8位数并包含数字和字母'));
        } else {
          callback();

        }
      };
      return {
        options: [{
          value: '1',
          label: '市城管局',
        },{
          value: '2',
          label: '市交通局',
        },{
          value: '3',
          label: '市交警局',
        },{
          value: '4',
          label: '南山区政府',
        },{
          value: '5',
          label: '宝安区政府',
        },],
        options1: [{
          value: '1',
          label: '审核',
        },{
          value: '2',
          label: '编辑',
        },{
          value: '3',
          label: '查看',
        }],
        props: {
          value: '4',
          label: '城管局',
          children: 'items'
        },
        ruleFormAdd: {
          "unitId": "",
          "userName": "",
          "mobile": "",
          "userPassword": "",
          "position": "",
          "account": "1",
          "operation": "",
          "userStatus": "1",
          "roleIds":[]
        },
        dialogFormVisibleAdd: false,
        rulesAdd: {
          mobile: [
            {validator: phoneCheck, }
          ],
          userPassword: [
            {validator: userPasswordCheck, }
          ],

        }
      }
    },
    created(){

    },
    methods: {

      //提交回调
      handleDiaSureAdd(){
        this.axios.post(process.env.API_HOST + '/systemUser/insert', {...this.ruleFormAdd})
          .then(response => {
            let result=response.data
            if (result.code == 200) {
              this.$message({
                type: 'success',
                message: '新增成功!'
              });
              this.dialogFormVisibleAdd = false
              this.$emit('getListInfo')
              this.resetForm('ruleFormAdd')
            }

          })
          .catch(error => {
            console.log(error);
          });
      },
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
//            this.handleDiaSureAdd()
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    }
  }
</script>

<style lang="stylus" rel="stylesheet/stylus" >
  @import "../../../common/stylus/mixin.styl"
  .buttonAddExit
    display inline-block
    margin-left 10px
    .el-dialog
      width:400px !important;
</style>
